﻿using System.Windows.Forms;
using System;
using Cepheus;
using BinaryClockScreensaver.Properties;

namespace BinaryClockScreensaver
{
    class Screensaver
    {
        public Screensaver()
        {
        }

        public bool Start(string[] args)
        {
            if (args.Length > 0)
            {
                if (args[0].ToLower().StartsWith("/p"))
                {
                    return false;
                }
                else if (args[0].ToLower().StartsWith("/c"))
                {
                    string strParent = args[0].Substring(args[0].IndexOf(":") + 1, args[0].Length - args[0].IndexOf(":") - 1);

                    int iParent = 0;
                    if (Int32.TryParse(strParent, out iParent))
                    {
                        IntPtr parent = new IntPtr(iParent);
                        MessageBox.Show(new Win32Window(parent), "No settings available.", "Binary Times", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }

                    return false;
                }
            }

            Start();
            return true;
        }

        private void Start()
        {
            Cursor.Hide();

            foreach (Screen screen in Screen.AllScreens)
            {
                FormScreensaver fs = new FormScreensaver();
                fs.Bounds = screen.Bounds;
                fs.FormClosed += new FormClosedEventHandler(fs_FormClosed);
                fs.Show();
            }
        }

        void fs_FormClosed(object sender, FormClosedEventArgs e)
        {
            Application.Exit();
        }
    }
}
